package xyz.jcat.sat.admin.dubbo;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import xyz.jcat.common.exception.BusinessException;
import xyz.jcat.common.web.RespCodeMsg;
import xyz.jcat.common.web.RespException;
import xyz.jcat.sat.admin.api.IAdminService;
import xyz.jcat.sat.admin.api.dto.AdminLoginDto;
import xyz.jcat.sat.admin.api.vo.AdminLoginSuccessVo;

import java.util.Objects;

@Slf4j
@DubboService
public class AdminService implements IAdminService {

    @Override
    public AdminLoginSuccessVo login(AdminLoginDto adminLoginDto) throws BusinessException {
        log.info("account: {}, password: {}", adminLoginDto.getAccount(), adminLoginDto.getPassword());
        AdminLoginSuccessVo adminLoginSuccessVo = new AdminLoginSuccessVo();
        adminLoginSuccessVo.setUserId(RandomUtil.randomLong());
        if(Objects.equals(adminLoginDto.getAccount(), "ex")) {
            throw new RespException(RespCodeMsg.ACCOUNT_OR_PWD_ERROR);
        }
        return adminLoginSuccessVo;
    }

}
